package com.defect.controller.management;


import com.defect.bo.*;
import com.defect.po.BaseInfo;
import com.defect.service.managementSercvice.BaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;

@RestController
public class TaskListController {
    @Autowired
    private BaseInfoService baseInfoService;

    @RequestMapping("/searchBaseInfoList")
    public ResultBoDu searchBaseInfoList(BaseInfoListSearch baseInfoListSearch, Integer pageIndex, Integer pageSize){
        PageDetail pageDetail = baseInfoService.searchBaseInfoList(baseInfoListSearch, pageIndex, pageSize);
        return new ResultBoDu("200","缺陷列表",pageDetail);
    }
//    用户的缺陷处理列表
    @RequestMapping("/searchUserBaseInfoList")
    public ResultBoDu searchUserBaseInfoList(UserBaseInfoListSearch userBaseInfoListSearch, Integer pageIndex, Integer pageSize){
//        这里需要登录获取user信息
        int userId = 2;
        PageDetail pageDetail = baseInfoService.searchUserBaseInfoList(userBaseInfoListSearch, pageIndex, pageSize,userId);
        return new ResultBoDu("200","缺陷列表",pageDetail);
    }
//    缺陷反馈列表
@RequestMapping("/searchCommentBaseInfoList")
public ResultBoDu searchCommentBaseInfoList(UserBaseInfoListSearch userBaseInfoListSearch, Integer pageIndex, Integer pageSize){
//        这里需要登录获取user信息

    PageDetail pageDetail = baseInfoService.searchCommentBaseInfoList(userBaseInfoListSearch, pageIndex, pageSize);
    return new ResultBoDu("200","缺陷列表",pageDetail);
}

    @RequestMapping("/deleteTaskArray")
    public ResultBoDu delTaskArray(@RequestBody ArrayList<Integer> list){
        System.out.println(list);
        int i = baseInfoService.delTaskArray(list);
        return new ResultBoDu("200","批量删除任务",i);
    }
    @RequestMapping("/delTask")
    public ResultBoDu delTask(int issueId){
        return new ResultBoDu("200","删除任务",baseInfoService.delTask(issueId));
    }
    @RequestMapping("/getAllProjects")
    public ResultBoDu getAllProjects() {
        return new ResultBoDu("200","加载项目",baseInfoService.getAllProjects());
    }
    @RequestMapping("/getAllStates")
    public ResultBoDu getAllStates() {
        return new ResultBoDu("200","加载状态",baseInfoService.getAllStates());
    }
    @RequestMapping("/getAllIssues")
    public ResultBoDu getAllIssues() {
        return new ResultBoDu("200","加载缺陷",baseInfoService.getAllIssues());
    }
    @RequestMapping("/getAllType")
    public ResultBoDu getAllType() {
        return new ResultBoDu("200","加载分类",baseInfoService.getAllType());
    }
    @RequestMapping("/getAllSeveritys")
    public ResultBoDu getAllSeveritys() {
        return new ResultBoDu("200","加载严重性",baseInfoService.getAllSeveritys());
    }
    @RequestMapping("/getAllPrioritys")
    public ResultBoDu getAllPrioritys() {
        return new ResultBoDu("200","加载优先级",baseInfoService.getAllPrioritys());
    }
    @RequestMapping("/checkIssueName")
    public ResultBoDu checkIssueName(String issueName){
        BaseInfo baseInfo = baseInfoService.checkIssueName(issueName);
        if (baseInfo==null){
            return new ResultBoDu("200","用户不存在",baseInfo);
        }else {
            return new ResultBoDu("400","用户已存在",baseInfo);
        }
    }
    @RequestMapping("/addBaseInfo")
    public ResultBoDu addBaseInfo(BaseInfo baseInfo){
        baseInfo.setIssueId(baseInfoService.getId());
        baseInfo.setIssueState("未指派");
        Date date = new Date();
        System.out.println(date);
        baseInfo.setCreateTime(date);
//        这里还需要添加当前用户
        System.out.println(baseInfo);
        int i = baseInfoService.addBaseInfo(baseInfo);
        if (i != 0){
            return new ResultBoDu("200","新增用户成功",i);
        }else {
            return new ResultBoDu("400","新增用户失败",i);
        }
    }
//    这里还需要修改人的信息和修改时间
    @RequestMapping("/changeBaseInfo")
    public ResultBoDu changeBaseInfo(BaseInfo baseInfo){
           return new ResultBoDu("200","修改用户成功",baseInfoService.changeBaseInfo(baseInfo));
    }
    @RequestMapping("/getuserarray")
    public ResultBoDu getUserArray(BaseInfo baseInfo){
        return new ResultBoDu("200","修改用户成功",baseInfoService.getUserArray(baseInfo));
    }
    @RequestMapping("/commitAllocation")
    public ResultBoDu commitAllocation(Integer issueId,Integer userId){
        return new ResultBoDu("200","分配成功",baseInfoService.commitAllocation(issueId,userId));
    }
    @RequestMapping("/commitDeal")
    public ResultBoDu commitAllocation(BaseInfoDealItem baseInfoDealItem){

        return new ResultBoDu("200","commit成功",baseInfoService.commitDeal(baseInfoDealItem));
    }
    @RequestMapping("/getLogByIssueId")
    public ResultBoDu getLogByIssueId(Integer issueId){
        return new ResultBoDu("200","commit成功",baseInfoService.getLogByIssueId(issueId));
    }
    @RequestMapping("/commentDeal")
    public ResultBoDu commentDeal(CommentBo commentBo){
        System.out.println("进入了commit contro");
        return new ResultBoDu("200","commit成功",baseInfoService.commentDeal(commentBo));
    }




}
